////////////////////////////////////////////////
// File: StoreController.java
// Description: Enter summary here after generation.
// Date: 2016-09-23 09:09:34
// Web: http://www.elanzhou.com/
////////////////////////////////////////////////
package com.mvc.controller;
import java.io.IOException;
import java.util.List;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mvc.entity.Meminfo;
import com.mvc.entity.Repertory;
//import com.mvc.entity.User;
//import com.mvc.entity.UserDetail;
import com.mvc.entity.Store;
import com.mvc.service.DictService;
import com.mvc.service.RepertoryService;
import com.mvc.service.StoreService;
import com.mvc.service.SyscateService;
import com.pub.MyJson;
import com.pub.Page;
import com.aspose.cells.Cells;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
@Controller
@RequestMapping("MemStore")
public class MemStoreController {
	protected final transient Log logger = LogFactory.getLog(MemStoreController.class);
	@Autowired
	private StoreService storeService;
	@Autowired
	private RepertoryService repertoryService;
	@Autowired
	private SyscateService syscateService;//品类service
	@Autowired
	private DictService dictService;

	public MemStoreController() {
	}

	/*根据仓库id看库存列表*/
	@RequestMapping("RepertoryStoreIndex.do")
	public String RepertoryStoreIndex(HttpSession session,HttpServletRequest request,ModelMap modelMap, String pageNo, String Ajax) {
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		String ID=request.getParameter("ID");//仓库id
		Repertory repertory=repertoryService.getRepertory(ID);
		modelMap.put("repertory", repertory);
		Page page = new Page();
		page.setPageNox(pageNo);
		page.setPageSize(15);
		page.setVal(",'Membername':'"+smeminfo.getMemname()+"'");
		String hql = "select a from Store a  where a.Membername='"+smeminfo.getMemname()+"' order by a.ID desc";
		List list = storeService.getStoreList(hql, page);
		String counthql = "select count(*) from Store a where a.Membername='"+smeminfo.getMemname()+"'";
		page.setPageCount(storeService.getCount(counthql, page));
		modelMap.put("page", page);
		modelMap.put("list", list);
		if (Ajax != null && Ajax.equals("Ajax")) {
			return "/MemStore/RepertoryStoreList";
		} else {
			return "/MemStore/RepertoryStoreIndex";
		}

	}
	/*根据仓库id添加库存*/ 
	@RequestMapping("RepertoryStoreAdd.do")
	public String RepertoryStoreAdd(HttpSession session,HttpServletRequest request,ModelMap modelMap)
	{
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		String ID=request.getParameter("ID");//仓库id
		Repertory repertory=repertoryService.getRepertory(ID);
		modelMap.put("repertory", repertory);
		List<Object> fcate=syscateService.getFcate() ;
		modelMap.put("fcate", fcate);
		Date date=new Date();
		DateFormat format=new SimpleDateFormat("yyyy-MM-dd");
		String dqsj=format.format(date);
		modelMap.put("dqsj", dqsj);
		List hylist=dictService.getAllByKeyname("规格");		
		modelMap.put("hylist",hylist);
		List statuslist=dictService.getAllByKeyname("库存状态");		
		modelMap.put("statuslist",statuslist);
		List dolist=dictService.getAllByKeyname("操作类型");		
		modelMap.put("dolist",dolist);
		return "/MemStore/RepertoryStoreAdd";
	}
	
	/*
	 * 根据仓库id保存*/
	@RequestMapping("RepertoryStoreSave.do")
	public void RepertoryStoreSave(HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap, HttpSession session) {
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		try {
			
			Store  store= new Store();
			boolean tag=true;
		    String Msg="信息保存成功";
             
               if(tag){
                              
               String FieldFname=(String)request.getParameter("Fname");
             
               if(((FieldFname!=null)&(!FieldFname.trim().equals("")))){
            	   FieldFname=FieldFname.trim();
                    store.setFname(FieldFname);
                  
        		}else
        		{
        			tag=false;
        			Msg="品类不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldCatename=(String)request.getParameter("Catename");
             
               if(((FieldCatename!=null)&(!FieldCatename.trim().equals("")))){
            	   FieldCatename=FieldCatename.trim();
                    store.setCatename(FieldCatename);
                  
        		}else
        		{
        			tag=false;
        			Msg="品种不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldSpec=(String)request.getParameter("Spec");
             
               if(((FieldSpec!=null)&(!FieldSpec.trim().equals("")))){
            	   FieldSpec=FieldSpec.trim();
                    store.setSpec(FieldSpec);
                  
        		}else
        		{
        			tag=false;
        			Msg="规格不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldAddress=(String)request.getParameter("Address");
             
               if(((FieldAddress!=null)&(!FieldAddress.trim().equals("")))){
            	   FieldAddress=FieldAddress.trim();
                    store.setAddress(FieldAddress);
                  
        		}else
        		{
        			tag=false;
        			Msg="产地不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldGoodsnum=(String)request.getParameter("Goodsnum");
             
               if(((FieldGoodsnum!=null)&(!FieldGoodsnum.trim().equals("")))){
            	   FieldGoodsnum=FieldGoodsnum.trim();
                    store.setGoodsnum(FieldGoodsnum);
                  
        		}else
        		{
        			tag=false;
        			Msg="数量不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldDeptname=(String)request.getParameter("Deptname");
             
               if(((FieldDeptname!=null)&(!FieldDeptname.trim().equals("")))){
            	   FieldDeptname=FieldDeptname.trim();
                    store.setDeptname(FieldDeptname);
                  
        		}else
        		{
        			tag=false;
        			Msg="单位不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldRepertoryid=(String)request.getParameter("Repertoryid");
             
               if(((FieldRepertoryid!=null)&(!FieldRepertoryid.trim().equals("")))){
            	   FieldRepertoryid=FieldRepertoryid.trim();
                    store.setRepertoryid(FieldRepertoryid);
                  
        		}else
        		{
        			tag=false;
        			Msg="仓库编号不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldRepertoryname=(String)request.getParameter("Repertoryname");
             
               if(((FieldRepertoryname!=null)&(!FieldRepertoryname.trim().equals("")))){
            	   FieldRepertoryname=FieldRepertoryname.trim();
                    store.setRepertoryname(FieldRepertoryname);
                  
        		}else
        		{
        			tag=false;
        			Msg="仓库不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldGoodsstatus=(String)request.getParameter("Goodsstatus");
             
               if(((FieldGoodsstatus!=null)&(!FieldGoodsstatus.trim().equals("")))){
            	   FieldGoodsstatus=FieldGoodsstatus.trim();
                    store.setGoodsstatus(FieldGoodsstatus);
                  
        		}else
        		{
        			tag=false;
        			Msg="状态不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldGoodsdate=(String)request.getParameter("Goodsdate");
             
               if(((FieldGoodsdate!=null)&(!FieldGoodsdate.trim().equals("")))){
            	   FieldGoodsdate=FieldGoodsdate.trim();
                    store.setGoodsdate(FieldGoodsdate);
                  
        		}else
        		{
        			tag=false;
        			Msg="操作日期不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldGoodstype=(String)request.getParameter("Goodstype");
             
               if(((FieldGoodstype!=null)&(!FieldGoodstype.trim().equals("")))){
            	   FieldGoodstype=FieldGoodstype.trim();
                    store.setGoodstype(FieldGoodstype);
                  
        		}else
        		{
        			tag=false;
        			Msg="操作类型不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldMembername=(String)request.getParameter("Membername");
             
               if(((FieldMembername!=null)&(!FieldMembername.trim().equals("")))){
            	   FieldMembername=FieldMembername.trim();
                    store.setMembername(FieldMembername);
                  
        		}else
        		{
        			tag=false;
        			Msg="操作人不能为空！";
        		}
        		}
	         
            
            MyJson mj=new MyJson();
              if(tag){
                     storeService.Save(store);	 
        			 mj.setStatusCode(200);
        		 }else
        		 {
        			 mj.setStatusCode(300);
        		 }
             mj.setMessage(Msg);
             mj.setForwardUrl("/MemStore/RepertoryStoreIndex.do?ID="+(String)request.getParameter("Repertoryid"));
             mj.setCallbackType("forward");
             String str=mj.getJson();
			 response.getWriter().print(str);
		} catch (Exception e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		}
	} 
	
	/*根据仓库id编辑*/
	@RequestMapping("RepertoryStoreEdit.do")
	public String RepertoryStoreEdit(HttpSession session,HttpServletRequest request,ModelMap modelMap)
	{
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		String ID=request.getParameter("ID");
		Store store=(Store)storeService.getStore(ID);
		modelMap.put("store", store);
				
		List<Object> fcate=syscateService.getFcate() ;
		modelMap.put("fcate", fcate);	
		List hylist=dictService.getAllByKeyname("规格");		
		modelMap.put("hylist",hylist);
		List statuslist=dictService.getAllByKeyname("库存状态");		
		modelMap.put("statuslist",statuslist);
		List dolist=dictService.getAllByKeyname("操作类型");		
		modelMap.put("dolist",dolist);
		
		return "/MemStore/RepertoryStoreEdit";
	}
	  /*编辑保存*/
		@RequestMapping("RepertoryStoreEditSave.do")
		public void RepertoryStoreEditSave(HttpServletResponse response, HttpServletRequest request,
				ModelMap modelMap,HttpSession session) {
			Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
			modelMap.put("smeminfo",smeminfo);
			
			try {
				String Id=(String)request.getParameter("ID");
				Store  store=(Store)storeService.getStore(Id);
				boolean tag=true;
			    String Msg="信息修改成功";
	             
	            if(tag){
	               
	               String FieldFname=(String)request.getParameter("Fname");
	             
	               if(((FieldFname!=null)&(!FieldFname.trim().equals("")))){
	            	   FieldFname=FieldFname.trim();
	                    store.setFname(FieldFname);
	                  
	        		}else
	        		{
	        			tag=false;
	        			Msg="品类不能为空！";
	        		}
	        		}
		         
	             
	            if(tag){
	               
	               String FieldCatename=(String)request.getParameter("Catename");
	             
	               if(((FieldCatename!=null)&(!FieldCatename.trim().equals("")))){
	            	   FieldCatename=FieldCatename.trim();
	                    store.setCatename(FieldCatename);
	                  
	        		}else
	        		{
	        			tag=false;
	        			Msg="品种不能为空！";
	        		}
	        		}
		         
	             
	            if(tag){
	               
	               String FieldSpec=(String)request.getParameter("Spec");
	             
	               if(((FieldSpec!=null)&(!FieldSpec.trim().equals("")))){
	            	   FieldSpec=FieldSpec.trim();
	                    store.setSpec(FieldSpec);
	                  
	        		}else
	        		{
	        			tag=false;
	        			Msg="规格不能为空！";
	        		}
	        		}
		         
	             
	            if(tag){
	               
	               String FieldAddress=(String)request.getParameter("Address");
	             
	               if(((FieldAddress!=null)&(!FieldAddress.trim().equals("")))){
	            	   FieldAddress=FieldAddress.trim();
	                    store.setAddress(FieldAddress);
	                  
	        		}else
	        		{
	        			tag=false;
	        			Msg="产地不能为空！";
	        		}
	        		}
		         
	             
	            if(tag){
	               
	               String FieldGoodsnum=(String)request.getParameter("Goodsnum");
	             
	               if(((FieldGoodsnum!=null)&(!FieldGoodsnum.trim().equals("")))){
	            	   FieldGoodsnum=FieldGoodsnum.trim();
	                    store.setGoodsnum(FieldGoodsnum);
	                  
	        		}else
	        		{
	        			tag=false;
	        			Msg="数量不能为空！";
	        		}
	        		}
		         
	             
	            if(tag){
	               
	               String FieldDeptname=(String)request.getParameter("Deptname");
	             
	               if(((FieldDeptname!=null)&(!FieldDeptname.trim().equals("")))){
	            	   FieldDeptname=FieldDeptname.trim();
	                    store.setDeptname(FieldDeptname);
	                  
	        		}else
	        		{
	        			tag=false;
	        			Msg="单位不能为空！";
	        		}
	        		}
		         
	             
	            if(tag){
	               
	               String FieldRepertoryid=(String)request.getParameter("Repertoryid");
	             
	               if(((FieldRepertoryid!=null)&(!FieldRepertoryid.trim().equals("")))){
	            	   FieldRepertoryid=FieldRepertoryid.trim();
	                    store.setRepertoryid(FieldRepertoryid);
	                  
	        		}else
	        		{
	        			tag=false;
	        			Msg="仓库编号不能为空！";
	        		}
	        		}
		         
	             
	            if(tag){
	               
	               String FieldRepertoryname=(String)request.getParameter("Repertoryname");
	             
	               if(((FieldRepertoryname!=null)&(!FieldRepertoryname.trim().equals("")))){
	            	   FieldRepertoryname=FieldRepertoryname.trim();
	                    store.setRepertoryname(FieldRepertoryname);
	                  
	        		}else
	        		{
	        			tag=false;
	        			Msg="仓库不能为空！";
	        		}
	        		}
		         
	             
	            if(tag){
	               
	               String FieldGoodsstatus=(String)request.getParameter("Goodsstatus");
	             
	               if(((FieldGoodsstatus!=null)&(!FieldGoodsstatus.trim().equals("")))){
	            	   FieldGoodsstatus=FieldGoodsstatus.trim();
	                    store.setGoodsstatus(FieldGoodsstatus);
	                  
	        		}else
	        		{
	        			tag=false;
	        			Msg="状态不能为空！";
	        		}
	        		}
		         
	             
	            if(tag){
	               
	               String FieldGoodsdate=(String)request.getParameter("Goodsdate");
	             
	               if(((FieldGoodsdate!=null)&(!FieldGoodsdate.trim().equals("")))){
	            	   FieldGoodsdate=FieldGoodsdate.trim();
	                    store.setGoodsdate(FieldGoodsdate);
	                  
	        		}else
	        		{
	        			tag=false;
	        			Msg="操作日期不能为空！";
	        		}
	        		}
		         
	             
	            if(tag){
	               
	               String FieldGoodstype=(String)request.getParameter("Goodstype");
	             
	               if(((FieldGoodstype!=null)&(!FieldGoodstype.trim().equals("")))){
	            	   FieldGoodstype=FieldGoodstype.trim();
	                    store.setGoodstype(FieldGoodstype);
	                  
	        		}else
	        		{
	        			tag=false;
	        			Msg="操作类型不能为空！";
	        		}
	        		}
		         
	             
	            if(tag){
	               
	               String FieldMembername=(String)request.getParameter("Membername");
	             
	               if(((FieldMembername!=null)&(!FieldMembername.trim().equals("")))){
	            	   FieldMembername=FieldMembername.trim();
	                    store.setMembername(smeminfo.getMemname());
	                  
	        		}else
	        		{
	        			tag=false;
	        			Msg="操作人不能为空！";
	        		}
	        		}
		         
	            
	            MyJson mj=new MyJson();
	              if(tag){
	                     storeService.EditSave(store);	 
	        			 mj.setStatusCode(200);
	        		 }else
	        		 {
	        			 mj.setStatusCode(300);
	        		 }
	             mj.setMessage(Msg);
	             mj.setForwardUrl("/MemStore/RepertoryStoreIndex.do?ID="+(String)request.getParameter("Repertoryid"));
	             mj.setCallbackType("forward");
	             String str=mj.getJson();
				 response.getWriter().print(str);
			} catch (Exception e) {
				logger.error(e.getMessage());
				e.printStackTrace();
			}
		} 
	
	/*列表*/
	@RequestMapping("Index.do")
	public String Index(HttpSession session,ModelMap modelMap, String pageNo, String Ajax) {
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		Page page = new Page();
		page.setPageNox(pageNo);
		page.setPageSize(15);		
		String hql = "select a from Store a where a.Deptname='"+smeminfo.getCompanyname()+"' order by a.ID desc";
		List list = storeService.getStoreList(hql, page);
		String counthql = "select count(*) from Store a  where a.Deptname='"+smeminfo.getCompanyname()+"' ";
		page.setPageCount(storeService.getCount(counthql, page));
		modelMap.put("page", page);
		modelMap.put("list", list);
		if (Ajax != null && Ajax.equals("Ajax")) {
			return "/MemStore/List";
		} else {
			return "/MemStore/Index";
		}

	}
	
	/*列表*/
	@RequestMapping("Dy.do")
	public String Dy(HttpSession session,ModelMap modelMap, String pageNo, String Ajax) {
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		Page page = new Page();
		page.setPageNox(pageNo);
		page.setPageSize(15);		
		String hql = "select a from Store a where a.Deptname='"+smeminfo.getCompanyname()+"' and a.Goodsstatus='已抵押' order by a.ID desc";
		List list = storeService.getStoreList(hql, page);
		String counthql = "select count(*) from Store a  where a.Deptname='"+smeminfo.getCompanyname()+"'  and a.Goodsstatus='已抵押'";
		page.setPageCount(storeService.getCount(counthql, page));
		modelMap.put("page", page);
		modelMap.put("list", list);
		if (Ajax != null && Ajax.equals("Ajax")) {
			return "/MemStore/List";
		} else {
			return "/MemStore/Dy";
		}

	}	
	
	/*列表*/
	@RequestMapping("Ddy.do")
	public String Ddy(HttpSession session,ModelMap modelMap, String pageNo, String Ajax) {
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		Page page = new Page();
		page.setPageNox(pageNo);
		page.setPageSize(15);		
		String hql = "select a from Store a where a.Deptname='"+smeminfo.getCompanyname()+"' and a.Goodsstatus='待抵押' order by a.ID desc";
		List list = storeService.getStoreList(hql, page);
		String counthql = "select count(*) from Store a  where a.Deptname='"+smeminfo.getCompanyname()+"'  and a.Goodsstatus='待抵押'";
		page.setPageCount(storeService.getCount(counthql, page));
		modelMap.put("page", page);
		modelMap.put("list", list);
		if (Ajax != null && Ajax.equals("Ajax")) {
			return "/MemStore/List";
		} else {
			return "/MemStore/Ddy";
		}

	}	
	/*列表*/
	@RequestMapping("Zc.do")
	public String Zc(HttpSession session,ModelMap modelMap, String pageNo, String Ajax) {
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		Page page = new Page();
		page.setPageNox(pageNo);
		page.setPageSize(15);		
		String hql = "select a from Store a where a.Deptname='"+smeminfo.getCompanyname()+"' and a.Goodsstatus='正常' order by a.ID desc";
		List list = storeService.getStoreList(hql, page);
		String counthql = "select count(*) from Store a  where a.Deptname='"+smeminfo.getCompanyname()+"'  and a.Goodsstatus='正常'";
		page.setPageCount(storeService.getCount(counthql, page));
		modelMap.put("page", page);
		modelMap.put("list", list);
		if (Ajax != null && Ajax.equals("Ajax")) {
			return "/MemStore/List";
		} else {
			return "/MemStore/Zc";
		}

	}	
	
	/*列表*/
	@RequestMapping("Wsh.do")
	public String Wsh(HttpSession session,ModelMap modelMap, String pageNo, String Ajax) {
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		Page page = new Page();
		page.setPageNox(pageNo);
		page.setPageSize(15);		
		String hql = "select a from Store a where a.Deptname='"+smeminfo.getCompanyname()+"' and a.Goodsstatus='未审核' order by a.ID desc";
		List list = storeService.getStoreList(hql, page);
		String counthql = "select count(*) from Store a  where a.Deptname='"+smeminfo.getCompanyname()+"'  and a.Goodsstatus='未审核'";
		page.setPageCount(storeService.getCount(counthql, page));
		modelMap.put("page", page);
		modelMap.put("list", list);
		if (Ajax != null && Ajax.equals("Ajax")) {
			return "/MemStore/List";
		} else {
			return "/MemStore/Wsh";
		}

	}	
	/*添加*/ 
	@RequestMapping("Add.do")
	public String Add(HttpSession session,ModelMap modelMap)
	{
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		List<Object> repertorylist=repertoryService.getListByHql("select a from Repertory a order by a.ID desc");
		modelMap.put("repertorylist", repertorylist);
		List<Object> fcate=syscateService.getFcate() ;
		modelMap.put("fcate", fcate);
		Date date=new Date();
		DateFormat format=new SimpleDateFormat("yyyy-MM-dd");
		String dqsj=format.format(date);
		modelMap.put("dqsj", dqsj);
		List hylist=dictService.getAllByKeyname("规格");		
		modelMap.put("hylist",hylist);
		List statuslist=dictService.getAllByKeyname("库存状态");		
		modelMap.put("statuslist",statuslist);
		List dolist=dictService.getAllByKeyname("操作类型");		
		modelMap.put("dolist",dolist);
		return "/MemStore/Add";
	}
	/*保存*/
	@RequestMapping("Save.do")
	public void Save(HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap, HttpSession session) {
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		try {
			
			Store  store= new Store();
			boolean tag=true;
		    String Msg="信息保存成功";
             
               if(tag){
                              
               String FieldFname=(String)request.getParameter("Fname");
             
               if(((FieldFname!=null)&(!FieldFname.trim().equals("")))){
            	   FieldFname=FieldFname.trim();
                    store.setFname(FieldFname);
                  
        		}else
        		{
        			tag=false;
        			Msg="品类不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldCatename=(String)request.getParameter("Catename");
             
               if(((FieldCatename!=null)&(!FieldCatename.trim().equals("")))){
            	   FieldCatename=FieldCatename.trim();
                    store.setCatename(FieldCatename);
                  
        		}else
        		{
        			tag=false;
        			Msg="品种不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldSpec=(String)request.getParameter("Spec");
             
               if(((FieldSpec!=null)&(!FieldSpec.trim().equals("")))){
            	   FieldSpec=FieldSpec.trim();
                    store.setSpec(FieldSpec);
                  
        		}else
        		{
        			tag=false;
        			Msg="规格不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldAddress=(String)request.getParameter("Address");
             
               if(((FieldAddress!=null)&(!FieldAddress.trim().equals("")))){
            	   FieldAddress=FieldAddress.trim();
                    store.setAddress(FieldAddress);
                  
        		}else
        		{
        			tag=false;
        			Msg="产地不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldGoodsnum=(String)request.getParameter("Goodsnum");
             
               if(((FieldGoodsnum!=null)&(!FieldGoodsnum.trim().equals("")))){
            	   FieldGoodsnum=FieldGoodsnum.trim();
                    store.setGoodsnum(FieldGoodsnum);
                  
        		}else
        		{
        			tag=false;
        			Msg="数量不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldDeptname=(String)request.getParameter("Deptname");
             
               if(((FieldDeptname!=null)&(!FieldDeptname.trim().equals("")))){
            	   FieldDeptname=FieldDeptname.trim();
                    store.setDeptname(FieldDeptname);
                  
        		}else
        		{
        			tag=false;
        			Msg="单位不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldRepertoryid=(String)request.getParameter("Repertoryid");
             
               if(((FieldRepertoryid!=null)&(!FieldRepertoryid.trim().equals("")))){
            	   FieldRepertoryid=FieldRepertoryid.trim();
                    store.setRepertoryid(FieldRepertoryid);
                  
        		}else
        		{
        			tag=false;
        			Msg="仓库编号不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldRepertoryname=(String)request.getParameter("Repertoryname");
             
               if(((FieldRepertoryname!=null)&(!FieldRepertoryname.trim().equals("")))){
            	   FieldRepertoryname=FieldRepertoryname.trim();
                    store.setRepertoryname(FieldRepertoryname);
                  
        		}else
        		{
        			tag=false;
        			Msg="仓库不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldGoodsstatus=(String)request.getParameter("Goodsstatus");
             
               if(((FieldGoodsstatus!=null)&(!FieldGoodsstatus.trim().equals("")))){
            	   FieldGoodsstatus=FieldGoodsstatus.trim();
                    store.setGoodsstatus(FieldGoodsstatus);
                  
        		}else
        		{
        			tag=false;
        			Msg="状态不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldGoodsdate=(String)request.getParameter("Goodsdate");
             
               if(((FieldGoodsdate!=null)&(!FieldGoodsdate.trim().equals("")))){
            	   FieldGoodsdate=FieldGoodsdate.trim();
                    store.setGoodsdate(FieldGoodsdate);
                  
        		}else
        		{
        			tag=false;
        			Msg="操作日期不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldGoodstype=(String)request.getParameter("Goodstype");
             
               if(((FieldGoodstype!=null)&(!FieldGoodstype.trim().equals("")))){
            	   FieldGoodstype=FieldGoodstype.trim();
                    store.setGoodstype(FieldGoodstype);
                  
        		}else
        		{
        			tag=false;
        			Msg="操作类型不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldMembername=(String)request.getParameter("Membername");
             
               if(((FieldMembername!=null)&(!FieldMembername.trim().equals("")))){
            	   FieldMembername=FieldMembername.trim();
                    store.setMembername(FieldMembername);
                  
        		}else
        		{
        			tag=false;
        			Msg="操作人不能为空！";
        		}
        		}
	         
            
            MyJson mj=new MyJson();
              if(tag){
                     storeService.Save(store);	 
        			 mj.setStatusCode(200);
        		 }else
        		 {
        			 mj.setStatusCode(300);
        		 }
             mj.setMessage(Msg);
             mj.setForwardUrl("/MemStore/Index.do");
             mj.setCallbackType("forward");
             String str=mj.getJson();
			 response.getWriter().print(str);
		} catch (Exception e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		}
	} 
    
	/*编辑*/
	@RequestMapping("Edit.do")
	public String Edit(HttpSession session,HttpServletRequest request,ModelMap modelMap)
	{
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		String ID=request.getParameter("ID");
		Store store=(Store)storeService.getStore(ID);
		modelMap.put("store", store);
		
		List<Object> repertorylist=repertoryService.getListByHql("select a from Repertory a order by a.ID desc");
		modelMap.put("repertorylist", repertorylist);
		List<Object> fcate=syscateService.getFcate() ;
		modelMap.put("fcate", fcate);	
		List hylist=dictService.getAllByKeyname("规格");		
		modelMap.put("hylist",hylist);
		List statuslist=dictService.getAllByKeyname("库存状态");		
		modelMap.put("statuslist",statuslist);
		List dolist=dictService.getAllByKeyname("操作类型");		
		modelMap.put("dolist",dolist);
		
		return "/MemStore/Edit";
	}
    
    /*编辑保存*/
	@RequestMapping("EditSave.do")
	public void EditSave(HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap,HttpSession session) {
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		try {
			String Id=(String)request.getParameter("ID");
			Store  store=(Store)storeService.getStore(Id);
			boolean tag=true;
		    String Msg="信息修改成功";
             
            if(tag){
               
               String FieldFname=(String)request.getParameter("Fname");
             
               if(((FieldFname!=null)&(!FieldFname.trim().equals("")))){
            	   FieldFname=FieldFname.trim();
                    store.setFname(FieldFname);
                  
        		}else
        		{
        			tag=false;
        			Msg="品类不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldCatename=(String)request.getParameter("Catename");
             
               if(((FieldCatename!=null)&(!FieldCatename.trim().equals("")))){
            	   FieldCatename=FieldCatename.trim();
                    store.setCatename(FieldCatename);
                  
        		}else
        		{
        			tag=false;
        			Msg="品种不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldSpec=(String)request.getParameter("Spec");
             
               if(((FieldSpec!=null)&(!FieldSpec.trim().equals("")))){
            	   FieldSpec=FieldSpec.trim();
                    store.setSpec(FieldSpec);
                  
        		}else
        		{
        			tag=false;
        			Msg="规格不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldAddress=(String)request.getParameter("Address");
             
               if(((FieldAddress!=null)&(!FieldAddress.trim().equals("")))){
            	   FieldAddress=FieldAddress.trim();
                    store.setAddress(FieldAddress);
                  
        		}else
        		{
        			tag=false;
        			Msg="产地不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldGoodsnum=(String)request.getParameter("Goodsnum");
             
               if(((FieldGoodsnum!=null)&(!FieldGoodsnum.trim().equals("")))){
            	   FieldGoodsnum=FieldGoodsnum.trim();
                    store.setGoodsnum(FieldGoodsnum);
                  
        		}else
        		{
        			tag=false;
        			Msg="数量不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldDeptname=(String)request.getParameter("Deptname");
             
               if(((FieldDeptname!=null)&(!FieldDeptname.trim().equals("")))){
            	   FieldDeptname=FieldDeptname.trim();
                    store.setDeptname(FieldDeptname);
                  
        		}else
        		{
        			tag=false;
        			Msg="单位不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldRepertoryid=(String)request.getParameter("Repertoryid");
             
               if(((FieldRepertoryid!=null)&(!FieldRepertoryid.trim().equals("")))){
            	   FieldRepertoryid=FieldRepertoryid.trim();
                    store.setRepertoryid(FieldRepertoryid);
                  
        		}else
        		{
        			tag=false;
        			Msg="仓库编号不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldRepertoryname=(String)request.getParameter("Repertoryname");
             
               if(((FieldRepertoryname!=null)&(!FieldRepertoryname.trim().equals("")))){
            	   FieldRepertoryname=FieldRepertoryname.trim();
                    store.setRepertoryname(FieldRepertoryname);
                  
        		}else
        		{
        			tag=false;
        			Msg="仓库不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldGoodsstatus=(String)request.getParameter("Goodsstatus");
             
               if(((FieldGoodsstatus!=null)&(!FieldGoodsstatus.trim().equals("")))){
            	   FieldGoodsstatus=FieldGoodsstatus.trim();
                    store.setGoodsstatus(FieldGoodsstatus);
                  
        		}else
        		{
        			tag=false;
        			Msg="状态不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldGoodsdate=(String)request.getParameter("Goodsdate");
             
               if(((FieldGoodsdate!=null)&(!FieldGoodsdate.trim().equals("")))){
            	   FieldGoodsdate=FieldGoodsdate.trim();
                    store.setGoodsdate(FieldGoodsdate);
                  
        		}else
        		{
        			tag=false;
        			Msg="操作日期不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldGoodstype=(String)request.getParameter("Goodstype");
             
               if(((FieldGoodstype!=null)&(!FieldGoodstype.trim().equals("")))){
            	   FieldGoodstype=FieldGoodstype.trim();
                    store.setGoodstype(FieldGoodstype);
                  
        		}else
        		{
        			tag=false;
        			Msg="操作类型不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldMembername=(String)request.getParameter("Membername");
             
               if(((FieldMembername!=null)&(!FieldMembername.trim().equals("")))){
            	   FieldMembername=FieldMembername.trim();
                    store.setMembername(smeminfo.getMemname());
                  
        		}else
        		{
        			tag=false;
        			Msg="操作人不能为空！";
        		}
        		}
	         
            
            MyJson mj=new MyJson();
              if(tag){
                     storeService.EditSave(store);	 
        			 mj.setStatusCode(200);
        		 }else
        		 {
        			 mj.setStatusCode(300);
        		 }
             mj.setMessage(Msg);
             mj.setForwardUrl("/MemStore/Index.do");
             mj.setCallbackType("forward");
             String str=mj.getJson();
			 response.getWriter().print(str);
		} catch (Exception e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		}
	} 
    
	/*删除*/
	@RequestMapping("Del.do")
	public void Del(HttpSession session,HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap) {
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
             String ID=request.getParameter("ID");
             storeService.Del(ID);
             String Msg="数据删除成功";
             MyJson mj=new MyJson();
             mj.setStatusCode(200);
             mj.setMessage(Msg);
             mj.setForwardUrl("/MemStore/Index.do");
             mj.setCallbackType("forward");
             String str=mj.getJson();
             try {
                  response.getWriter().print(str);
                 } catch (IOException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
                 }
	      }
          	/*编辑*/
	@RequestMapping("Detail.do")
	public String Detail(HttpSession session,HttpServletRequest request,ModelMap modelMap)
	{
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		String ID=request.getParameter("ID");
		Store store=(Store)storeService.getStore(ID);
		modelMap.put("store", store);
		return "/MemStore/Detail";
	}
    
 
}
